<template>
	<!-- 展示 -->
	<view v-if="orgDetailInfo!==null" style="margin: 20rpx;">
		<view>
			<img :src="orgDetailInfo.organAvatar" alt="社团封面" style="width: 100%;height: 400rpx;">
		</view>
		<h3 style="text-align: center;">{{orgDetailInfo.organName}}</h3>
		<view style="margin-top: 20rpx;font-size: smaller;color: #808080;">
			{{orgDetailInfo.organIntroduction}}
		</view>
		<!-- 社团核心成员介绍 -->
		<view style="margin-top: 40rpx;">
			<view v-if="orgDetailInfo.minister !== null"
				style="border-bottom: 1px solid #C0C0C0;padding-bottom: 20rpx;">
				<view>
					<view style="display: flex;justify-content: space-around">
						<view style="width: 20%;"><img style="max-width:100%;" :src="orgDetailInfo.minister.userAvatar"
								alt="">
						</view>
						<view style="width: 50%;">
							<view style="font-size: large;">{{orgDetailInfo.minister.userUsername}}
								<img v-if="orgDetailInfo.minister.userSex==1" style="width: 40rpx;margin-left: 10rpx;"
									src="../../static/tabbar/male.png" alt="">
								<img v-if="orgDetailInfo.minister.userSex==0" style="width: 40rpx;margin-left: 10rpx;"
									src="../../static/tabbar/female.png" alt="">
							</view>
							<view style="font-size: smaller;color: #808080;margin-top: 10rpx;">
								手机号:{{orgDetailInfo.minister.userPhone}}
							</view>
						</view>
						<view style="width: 18%;">
							<uni-tag text="社长" type="error"></uni-tag>
						</view>
					</view>
					<view style="text-align: center;font-size: smaller;color: #808080;">
						QQ：{{orgDetailInfo.minister.userQq!==null?orgDetailInfo.minister.userQq:'无'}} |
						微信：{{orgDetailInfo.minister.userVx!==null?orgDetailInfo.minister.userVx:'无'}}</view>
				</view>
			</view>
			<view v-if="orgDetailInfo.viceMinisters[0] !== null || orgDetailInfo.viceMinisters[1] !== null">
				<view v-if="orgDetailInfo.viceMinisters[0] !== null"
					style="border-bottom: 1px solid #C0C0C0;padding-bottom: 20rpx;margin-top: 18rpx;">
					<view style="display: flex;justify-content: space-around">
						<view style="width: 20%;"><img style="max-width:100%;"
								:src="orgDetailInfo.viceMinisters[0].userAvatar" alt="">
						</view>
						<view style="width: 50%;">
							<view style="font-size: large;">{{orgDetailInfo.viceMinisters[0].userUsername}}
								<img v-if="orgDetailInfo.viceMinisters[0].userSex==1"
									style="width: 40rpx;margin-left: 10rpx;" src="../../static/tabbar/male.png" alt="">
								<img v-if="orgDetailInfo.viceMinisters[0].userSex==0"
									style="width: 40rpx;margin-left: 10rpx;" src="../../static/tabbar/female.png"
									alt="">
							</view>
							<view style="font-size: smaller;color: #808080;margin-top: 10rpx;">
								手机号:{{orgDetailInfo.viceMinisters[0].userPhone}}
							</view>
						</view>
						<view style="width: 22%;">
							<uni-tag text="副社长" type="success"></uni-tag>
						</view>
					</view>
					<view style="text-align: center;font-size: smaller;color: #808080;">
						QQ：{{orgDetailInfo.viceMinisters[0].userQq!==null?orgDetailInfo.viceMinisters[0].userQq:'无'}} |
						微信：{{orgDetailInfo.viceMinisters[0].userVx!==null?orgDetailInfo.viceMinisters[0].userVx:'无'}}
					</view>
				</view>
				<view v-if="orgDetailInfo.viceMinisters[1] !== null"
					style="border-bottom: 1px solid #C0C0C0;padding-bottom: 20rpx;margin-top: 18rpx;">
					<view style="display: flex;justify-content: space-around">
						<view style="width: 20%;"><img style="max-width:100%;"
								:src="orgDetailInfo.viceMinisters[1].userAvatar" alt="">
						</view>
						<view style="width: 50%;">
							<view style="font-size: large;">{{orgDetailInfo.viceMinisters[1].userUsername}}
								<img v-if="orgDetailInfo.viceMinisters[1].userSex==1"
									style="width: 40rpx;margin-left: 10rpx;" src="../../static/tabbar/male.png" alt="">
								<img v-if="orgDetailInfo.viceMinisters[1].userSex==0"
									style="width: 40rpx;margin-left: 10rpx;" src="../../static/tabbar/female.png"
									alt="">
							</view>
							<view style="font-size: smaller;color: #808080;margin-top: 10rpx;">
								手机号:{{orgDetailInfo.viceMinisters[1].userPhone}}
							</view>
						</view>
						<view style="width: 22%;">
							<uni-tag text="副社长" type="success"></uni-tag>
						</view>
					</view>
					<view style="text-align: center;font-size: smaller;color: #808080;">
						QQ：{{orgDetailInfo.viceMinisters[1].userQq!==null?orgDetailInfo.viceMinisters[1].userQq:'无'}} |
						微信：{{orgDetailInfo.viceMinisters[1].userVx!==null?orgDetailInfo.viceMinisters[1].userVx:'无'}}
					</view>
				</view>
			</view>
			<view v-if="orgDetailInfo.secretary !== null"
				style="border-bottom: 1px solid #C0C0C0;padding-bottom: 20rpx;margin-top: 18rpx;">
				<view style="display: flex;justify-content: space-around">
					<view style="width: 20%;"><img style="max-width:100%;" :src="orgDetailInfo.secretary.userAvatar"
							alt="">
					</view>
					<view style="width: 50%;">
						<view style="font-size: large;">{{orgDetailInfo.secretary.userUsername}}
							<img v-if="orgDetailInfo.secretary.userSex==1" style="width: 40rpx;margin-left: 10rpx;"
								src="../../static/tabbar/male.png" alt="">
							<img v-if="orgDetailInfo.secretary.userSex==0" style="width: 40rpx;margin-left: 10rpx;"
								src="../../static/tabbar/female.png" alt="">
						</view>
						<view style="font-size: smaller;color: #808080;margin-top: 10rpx;">
							手机号:{{orgDetailInfo.secretary.userPhone}}
						</view>
					</view>
					<view style="width: 22%;">
						<uni-tag text="团支书" type="primary"></uni-tag>
					</view>
				</view>
				<view style="text-align: center;font-size: smaller;color: #808080;">
					QQ：{{orgDetailInfo.secretary.userQq!==null?orgDetailInfo.secretary.userQq:'无'}} |
					微信：{{orgDetailInfo.secretary.userVx!==null?orgDetailInfo.secretary.userVx:'无'}}
				</view>
			</view>
		</view>
		<!-- 社团介绍 -->
		<view v-if="orgDetailInfo.organIntroductionDetail!==null" style="margin-bottom: 40rpx;">
			<view style="text-align: center;margin-top: 20rpx;font-size: larger;">社团介绍</view>
			<view style="font-size: smaller;margin-top: 12rpx;">{{orgDetailInfo.organIntroductionDetail}}</view>
		</view>
		<view v-for="(img,index) in orgDetailInfo.organIntroductionDetailAvatars" :key="index">
			<img style="width: 100%;" :src="img" alt="">
		</view>
		<!-- 申请加入社团 -->
		<button v-if="orgDetailInfo.status==0" type="primary" @click="apply">申请加入社团</button>
		<button v-else type="warn" disabled="">{{orgDetailInfo.status==1?'已经是社团成员':'已申请加入该社团'}}</button>
	</view>
</template>

<script>
	// navigate.vue页面接受参数
	export default {
		data() {
			return {
				orgId: null,
				orgDetailInfo: null,
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			this.orgId = option.orgId
			// 获取社团详情
			this.getOrgDetail()
		},
		onBackPress(e) {
			// 这里可以自定义返回逻辑，比如下面跳转其他页面
			uni.switchTab({
				url: '/pages/index/index'
			});
			return true
		},
		methods: {
			// 监听下拉刷新动作
			onPullDownRefresh() {
				// 重新获取数据
				this.getOrgDetail();
				// 结束下拉刷新
				setTimeout(function() {
					// 停止下拉刷新
					uni.stopPullDownRefresh();
				}, 1000);
			},
			// 申请加入社团
			apply() {
				var that = this;
				uni.showModal({
					title: '申请',
					content: `您确定要申请加入 ${this.orgDetailInfo.organName} 吗?`,
					success: function(res) {
						if (res.confirm) {
							// 发送请求
							that.$http.request({
								url: '/organizations/web/organization/apply',
								method: 'POST',
								data: {
									orgId: that.orgId
								}
							}).then(res => {
								res = res.data;
								if (res.result) {
									uni.showToast({
										title: '申请加入社团成功',
										mask: true,
										duration: 2000
									})
									// 获取消息通知
									that.check.checkMessage(that)
									// 重新加载数据
									that.getOrgDetail()
								} else {
									uni.showToast({
										title: res.msg,
										mask: true,
										duration: 2000,
										icon: 'none'
									})
								}
							})
						}
					}
				})
			},
			// 获取社团详情
			getOrgDetail() {
				this.$http.request({
					url: `/organizations/web/organization/orgDetail/${this.orgId}`
				}).then(res => {
					res = res.data;
					if (res.result) {
						this.orgDetailInfo = res.data
					} else {
						uni.showToast({
							title: '获取社团详情失败',
							mask: true,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style>
</style>
